package jhavelogger.parser;

import java.util.HashSet;

import jhavelogger.models.AcceptedConnection;
import jhavelogger.models.UnparsedLog;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

public class AcceptedConnectionFactoryTests extends LogFactoryTestingBase {

    private HashSet<LogMessageType> allowedLogMessageTypes;

    @Before
    public void setUp() throws Exception {
	super.setUp();
	this.factory = new AcceptedConnectionFactory();
	this.allowedLogMessageTypes = new HashSet<LogMessageType>();
	this.allowedLogMessageTypes.add(LogMessageType.ACCEPTEDCONNECTION);
    }

    @Test
    public void setsAllNeededProperties() {
	String line = "1/21/09 10:31 AM - INFO: Accepted connection 60 from 141.233.196.77";
	AcceptedConnection log = (AcceptedConnection) this.factory.create(new UnparsedLog("127.0.0.1", line));
	
	Assert.assertNotNull("A log object must be created", log);
	Assert.assertEquals("UID must match expected value", 60, log.getUid());
	Assert.assertEquals("IP must match expected value", "141.233.196.77", log.getIpAddress());
    }
    
    @Test
    public void parsesAcceptedConnectionLog() {
	Assert.assertTrue(this.factoryCreatesObject(LogMessageType.ACCEPTEDCONNECTION));
    }

    @Test
    public void doesNotParseOtherLogs() {
	Assert.assertNull(this
		.factoryDoesNotCreateObjectsOfTypesOtherThan(this.allowedLogMessageTypes));
    }
}
